{extend name="layout/common_layout" /}
{block name="body"}
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/goods/index')}">后序管理</a></li>
            <!--<li class=""><a href="{:url('admin/goods/add')}">添加商品</a></li>-->
            <li class="layui-this">编辑后序</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/goods/update')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属分类</label>
                        <div class="layui-input-block  cids">
                            <select name="fid" lay-verify="required"  id="cid">
                                {foreach name="getFloor" item="vo"}
                                <option value="{$vo.id}" {if condition="$article.fid==$vo.id"} selected="selected"{/if}>{$vo.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">类型</label>
                        <div class="layui-input-block">
                            <select name="type" lay-verify="required">
                                <option value="1" {if condition="$article.type==1"} selected="selected"{/if}>后道工序</option>
                                <option value="2" {if condition="$article.type==2"} selected="selected"{/if}>装订方式</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" value="{$article.name}" required  lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">计算类型</label>
                        <div class="layui-input-block">
                            <select name="calculationtype" lay-verify="required">
                                <option value="1" {if condition="$article.calculationtype==1"} selected="selected"{/if}>P</option>
                                <option value="2" {if condition="$article.calculationtype==2"} selected="selected"{/if}>㎡</option>
                                <option value="3" {if condition="$article.calculationtype==3"} selected="selected"{/if}>本</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">单价</label>
                        <div class="layui-input-block">
                            <input type="text" name="unitprice" value="{$article.unitprice}" required  lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">最低价</label>
                        <div class="layui-input-block">
                            <input type="text" name="minprice" value="{$article.minprice}" required  lay-verify="required" placeholder="" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="id" value="{$article.id}">
                            <button class="layui-btn" lay-submit lay-filter="*">更新</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
{/block}
{block name="js"}
<!--<script src="__JS__/kindeditor/kindeditor.config.js"></script>-->
<!--<script src="__JS__/kindeditor/kindeditor-all-min.js"></script>-->
<script src="__JS__/ueditor/ueditor.config.js"></script>
<script src="__JS__/ueditor/ueditor.all.min.js"></script>
{/block}
{block name="script"}
<script>
    //文件上传
    layui.upload({
        url: "/index.php/api/upload/upload",
        type: 'file',
        elem:'#attar',
        success: function (data) {
            if (data.error === 0) {
                document.getElementById('file').value = data.url;
            } else {
                layer.msg(data.message);
            }
        }
    });

    $(function() {
        var ue = UE.getEditor('content'),
            uploadEditor = UE.getEditor('upload-photo-btn'),
            photoListItem,
            uploadImage;

        uploadEditor.ready(function () {
            uploadEditor.setDisabled();
            uploadEditor.hide();
            uploadEditor.addListener('beforeInsertImage', function (t, arg) {
                $.each(arg, function (index, item) {
                    photoListItem = '<div class="photo-list"><input style="display: none;" type="text" name="photo[]" value="' + item.src + '" class="layui-input layui-input-inline">';
                    photoListItem += '<img src="' + item.src + '" style="width:100px;"/>';
                    photoListItem += '<button type="button" class="layui-btn layui-btn-danger remove-photo-btn">移除</button></div>';

                    $('#photo-container').append(photoListItem).on('click', '.remove-photo-btn', function () {

                        $(this).parent('.photo-list').remove();
                    });

                });
            });
        });

        $('#upload-photo-btn').on('click', function () {
            uploadImage = uploadEditor.getDialog("insertimage");
            uploadImage.open();
        });



        $('.remove-photo-btn').click(function(){

            $(this).parent('.photo-list').remove();
        });
    });
    $('.cids').on('click','dd',function(){
        $('#tid').siblings('div').find('input').val('请选择');
        var fid = $(this).attr('lay-value');
        var url = "{:url('type/getTypeinfo')}";
        $.ajax({
            url: url,
            data:{
                'fid' : fid
            },
            type: 'post',
            dataType:'JSON',
            success: function (data) {
                var html_str = '';
                if (data.code == 1) {
                    $.each(data['data'], function (idx, data) {
                        html_str +=  '<dd lay-value="'+data.id+'" onclick="gettypename('+data.id+',\''+data.name+'\')">'+data.name+'</dd>'
                    })
                }else {
                    html_str = '';
                }
                $('#tid').siblings('div').find('dl').html(html_str);

            }, error: function () {
                mui.alert("网络异常");
            }
        })
    })
    //点击种类
    function gettypename(tid, name)
    {
        $('#tid').find('option').val(tid);
        $('#tid').siblings('div').find('input').val(name);
    }
</script>
{/block}